import {adminRequest, userRequest} from "@/utils/request.ts";
import type {
    BuyMember,
    MemberInfoResp,
    MemberLoginForm,
    MemberLoginRespInfo,
    MemberLogoutResp, PageAdminMember, PageResp, RegisterInfo, ResetPassword, ResetPasswordResp,
    UpdateMember,
    UpdateMemberResp
} from "@/type/member.ts";
// 路径
enum API {
    LOGIN_URL = '/member/login',
    LOGOUT_URL = '/member/logout',
    MEMBER_INFO_URL = '/member/info/',
    UPDATE_MEMBER_INFORMATION = '/member/update',
    BUY_MEMBER_URL = '/member/update/buyMember',
    REST_PASSWORD_URL = '/member/restPassword',
    REGISTER_URL = '/member/register'
}

// 暴露函数
// 登录
export const reqMemberLogin = (data: MemberLoginForm) => userRequest.post<any, MemberLoginRespInfo>(API.LOGIN_URL, data)
// 登出
export const reqMemberLogout = () => userRequest.post<any, MemberLogoutResp>(API.LOGOUT_URL)
// 获取用户信息
export const reqMemberInfo = (memberId: number) => userRequest.get<any, MemberInfoResp>(`${API.MEMBER_INFO_URL}${memberId}`)
// 修改用户信息
export const updateMember = (member: UpdateMember) => userRequest.put<any, UpdateMemberResp>(API.UPDATE_MEMBER_INFORMATION, member)
// 注册
export const registerMember = (data: RegisterInfo) => userRequest.post<any, ResetPasswordResp>(API.REGISTER_URL, data)

// 购买会员
export const buyMember = (date: BuyMember) => userRequest.put<any, UpdateMemberResp>(API.BUY_MEMBER_URL, date)
// 重置密码
export const resetPassword = (data: ResetPassword) => userRequest.post<any, ResetPasswordResp>(API.REST_PASSWORD_URL, data)


// ADMIN_API
enum ADMIN_API {
    GET_PAGE_INFO_URL = '/admin/memberInfo/page',
    BUY_MEMBER_URL = '/admin/memberInfo/update/buyMember',
}

export const getPageAdminMembers = (pageData: PageAdminMember) => adminRequest.get<any, PageResp>(ADMIN_API.GET_PAGE_INFO_URL, {params: pageData})
// 购买会员
export const adminBuyMember = (date: BuyMember) => adminRequest.put<any, UpdateMemberResp>(ADMIN_API.BUY_MEMBER_URL, date)